Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Put the string to be echo'd in double quotes and see how you go.
awk can handle it all in a single invocation. as can grep as it happens, but stick with getting what you have working first.
Put the string to be echo'd in double quotes and see how you go.
awk can handle it all in a single invocation. as can grep as it happens, but stick with getting what you have working first.
my apologies but Im not grasping what you are saying to put into double quotes?
The grep command as posted outputs the entire string regardless of where the match lies.
Code:
_mon._tcp.tax.ex.example.com has SRV record 0 5 3000 mdb-nkj.ex2.example.com.
$1 $2 $3 $4 $5 $6 $7 $8 $9
Here is a hint. I've spelled out what syg00 (sorry...) is trying to post. Your splitting the string based on the location of each period (.). $1 is the first word from the start of the string to the first period and so on.
As for the SRV record from DNS, does the target field always contain the same number of dots? If not, you may want to count them from the right instead of from the left. So creating an array from a split() function would work for that. By the way, the output of the split() function is the length of the new array.
If you need several parts, you could be sure to use Bash or Zsh and then catch the output as an array. The use of tee is not needed if you use command substitution with the AWK script.
Code:
a=($(echo _mon._tcp.tax.ex.example.com has SRV record 0 5 3000 mdb-nkj.ex2.example.com. \
| awk -vr="record" '$0~r {l=split($NF,a,/\./); print a[l-4],a[l-3]}'))
echo Array element 0 = ${a[0]}
echo Array element 1 = ${a[1]}
Good Morning!
I have a requirement that I need to print a certain portion of a TXT record and I could use some help on how to determine the section to print.
Code:
sed.ex.example.com descriptive text "re=sed_ex&source=%24ext"
I need to be able to break this portion out so I can insert new info between the underscore _ and ex and print to screen.
Code:
sed.ex.example.com descriptive text "re=sed_<newinfo>ex&source=%24ext"
Is that even possible to do? Any help is much appreciated! Thanks!
You have been using Linux for four years now; using awk/sed/grep should be familiar to you, and there are MANY examples and tutorials you can find, including the advice you've been given before.
Why don't you post what YOU have written/done/tried, and tell us where you're stuck. Since this is your 'requirement', you must be working on it, right??? If it's always between an underscore and "ex", a sed replacement should be fairly trivial...have you tried that?
See "man awk" and scroll down to the split() function and you will see that it can operate on a single field and split that field into an array according to a specified pattern. It would be up to you to figure out the pattern and how to choose the appropriate parts of the array.
Can you provide several examples of full lines of input along with the corresponding desired output?
You have been using Linux for four years now; using awk/sed/grep should be familiar to you, and there are MANY examples and tutorials you can find, including the advice you've been given before.
Why don't you post what YOU have written/done/tried, and tell us where you're stuck. Since this is your 'requirement', you must be working on it, right??? If it's always between an underscore and "ex", a sed replacement should be fairly trivial...have you tried that?
Thank you for your reply! Im not very fluent with Linux even though my profile indicates that I joined this group 4yrs ago. Even though it has been 4yrs, Im still a beginner as I dont use Linux everyday.
My other post was using 'awk -F\.' which was splitting the string location by each period. This one is more of an insertion.
My apologies for asking a similar question. I didnt want to pollute the other post with a different scenario. I have used awk|grep but never sed. I will give that a try! Thank you again!
As for the SRV record from DNS, does the target field always contain the same number of dots? If not, you may want to count them from the right instead of from the left. So creating an array from a split() function would work for that. By the way, the output of the split() function is the length of the new array.
I just saw this today ... after I posted what I had done. Thank you for your reply!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.